﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ModelGymTauro;
using System.IO;

namespace ViewGymTauro
{
    public partial class Deportista_Buscar : Form
    {
        public List<Deportista> listaDep = new List<Deportista>();
        public Deportista_Buscar()
        {
            InitializeComponent();
            listaDep = IniciaSesion.gymMan.queryAllDeportista();
            refresh();
        }

        private void btnLimpiar_Click(object sender, EventArgs e)
        {
            this.Show();
            
            
        }

        public void refresh() {
            dataGridView1.Rows.Clear();
            listaDep = IniciaSesion.gymMan.queryAllDeportista();
            for (int i = 0; i < listaDep.Count; i++)
            {
                dataGridView1.Rows.Add(new string[] { listaDep[i].Id.ToString(), listaDep[i].Nombre.ToString(), listaDep[i].Apellido.ToString(), listaDep[i].Estado.ToString() });


            }
        
        
        }

      
        private void dataGridView1_Click(object sender, EventArgs e)
        {
           int selectRow = dataGridView1.SelectedRows[0].Index;
           Deportista dep = listaDep[selectRow];
           this.txtApellido.Text = dep.Apellido;
           this.txtDni.Text = dep.Dni;
           this.txtNombre.Text = dep.Nombre;
           this.txtCode.Text = dep.Id.ToString();
           this.textBoxInfoCorreo.Text = dep.Correo;
           this.textBoxInfoDireccion.Text = dep.Direccion;
           this.textBoxInfoTelefono.Text = dep.Telefono;
           MemoryStream mem = new MemoryStream(dep.Foto);
           this.pictureBox1.Image = Image.FromStream(mem);
           this.txtFechaNac.Text = dep.FechaNacimiento.ToShortDateString();
          
            
        }
        private void buttonBuscar_Click(object sender, EventArgs e)

        {
            Char sexo='0';
            if (!this.boxSexo.Capture) {
                if (!this.radioFem.Capture) sexo = 'F';
                else sexo = 'M';
            }
            String queryEstado = "sexo ="+ sexo;
            if (!this.boxEstado.Capture)
            {
                Console.WriteLine(estadoBox.Items[estadoBox.SelectedIndex].ToString());
                }
            String fechaDesde = "";
            String fechaHasta = "";
            if (!this.boxDateNac.Capture)
            {
                fechaDesde = this.dateTimePicker1.Value.ToShortDateString();
                fechaHasta = this.dateTimePicker2.Value.ToShortDateString();
            }
            int code = 0;
            if (!this.boxCode.Capture)
            {
                code = Int32.Parse(this.txtcodeSearch.Text);
                listaDep = new List<Deportista>();
                listaDep.Add(IniciaSesion.gymMan.queryDeportistaById(code));
            }
            refresh();
        }

        private void btnModify_Click(object sender, EventArgs e)
        {
            this.txtFechaNac.Enabled = true;
            this.txtApellido.Enabled = true;
            this.txtDni.Enabled = true;
            this.txtNombre.Enabled = true;
            this.txtCode.Enabled = true;
            this.textBoxInfoCorreo.Enabled = true;
            this.textBoxInfoDireccion.Enabled = true;
            this.textBoxInfoTelefono.Enabled = true;
        }

        

       

        
    }
}
